#include <QMouseEvent>

#include "FrakOutGraphicsView.h"

FrakOutGraphicsView::FrakOutGraphicsView(QWidget *parent) : QGraphicsView(parent)
{
}

void FrakOutGraphicsView::mouseMoveEvent(QMouseEvent *event)
{
    if (event->buttons() & Qt::LeftButton)
    {
        emit scenePositionClicked(mapToScene(event->pos()));
    }
}

void FrakOutGraphicsView::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton)
    {
        emit scenePositionClicked(mapToScene(event->pos()));
    }
}

void FrakOutGraphicsView::wheelEvent(QWheelEvent *event)
{
    if (event->modifiers() & Qt::ControlModifier)
    {
        double sgn = event->delta() > 0 ? 1.0 : -1.0;
        double zoomInc = -0.1 * sgn;

        event->accept();
        emit sceneZoomed(zoomInc);
    }
    else
        QGraphicsView::wheelEvent(event);
}

void FrakOutGraphicsView::slotZoom(double factor)
{
    resetTransform();
    scale(factor, factor);
}
